﻿using System.Windows;
using System.Windows.Controls;

namespace UI.Controls
{
    /// <summary>
    /// Interaction logic for AddCancel.xaml
    /// </summary>
    public partial class AddCancel : UserControl
    {
        public AddCancel()
        {
            InitializeComponent();
        }

        public event RoutedEventHandler AddClicked
        {
            add { AddHandler(AddClickedEvent, value); }
            remove { RemoveHandler(AddClickedEvent, value); }
        }
        public event RoutedEventHandler CancelClicked
        {
            add { AddHandler(CancelClickedEvent, value); }
            remove { RemoveHandler(CancelClickedEvent, value); }
        }

        public static readonly RoutedEvent AddClickedEvent = EventManager.RegisterRoutedEvent("AddClicked",
                                                                                             RoutingStrategy.Bubble,
                                                                                             typeof(RoutedEventHandler),
                                                                                             typeof(OkCancel));
        public static readonly RoutedEvent CancelClickedEvent = EventManager.RegisterRoutedEvent("CancelClicked",
                                                                                             RoutingStrategy.Bubble,
                                                                                             typeof(RoutedEventHandler),
                                                                                             typeof(OkCancel));

        void RaiseAddClickedEvent()
        {
            RoutedEventArgs args = new RoutedEventArgs(AddClickedEvent);
            RaiseEvent(args);
        }

        void RaiseCancelClickedEvent()
        {
            RoutedEventArgs args = new RoutedEventArgs(CancelClickedEvent);
            RaiseEvent(args);
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            FrameworkElement element = e.Source as FrameworkElement;
            if (element != null)
                switch (element.Name)
                {
                    case "AddButton":
                        RaiseAddClickedEvent();
                        break;
                    case "CancelButton":
                        RaiseCancelClickedEvent();
                        break;
                }
        }

        public bool IsCancelClose
        {
            get
            {
                return CancelButton.IsCancel;
            }
            set
            {
                CancelButton.IsCancel = value;
            }
        }
    }
}
